home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Graphics / Viewers / VideoStreamV1.0 / Source / aviDecodeSrc / xanim.h < prev   
Encoding:
C/C++ Source or Header  |  1995-06-12  |  9.7 KB  |  379 lines

  1.  
  2. /*
  3.  * xanim.h
  4.  *
  5.  * Copyright (C) 1990,1991,1992,1993 by Mark Podlipec. 
  6.  * All rights reserved.
  7.  *
  8.  * This software may be freely copied, modified and redistributed
  9.  * without fee provided that this copyright notice is preserved 
  10.  * intact on all copies and modified copies.
  11.  * 
  12.  * There is no warranty or other guarantee of fitness of this software.
  13.  * It is provided solely "as is". The author(s) disclaim(s) all
  14.  * responsibility and liability with respect to this software's usage
  15.  * or its effect upon hardware or computer systems.
  16.  *
  17.  */
  18.  
  19. /** WAR: Wildly hacked to stream AVI RGB data to stdout, 7/2/94 **/
  20.  
  21. #include <sys/types.h>
  22. #include <sys/param.h>
  23. #include <stdio.h>
  24. #include <stdlib.h>
  25.  
  26. #define LONG int
  27. #define ULONG unsigned int
  28. #define BYTE char
  29. #define UBYTE unsigned char
  30. #define SHORT short
  31. #define USHORT unsigned short
  32. #define WORD short int
  33. #define UWORD unsigned short int
  34.  
  35. #define TRUE 1
  36. #define FALSE 0
  37.  
  38. #ifndef MIN
  39. #define MIN(x,y)    ( ((x)>(y))?(y):(x) )
  40. #endif
  41.  
  42. #ifndef MAX
  43. #define MAX(x,y)    ( ((x)>(y))?(x):(y) )
  44. #endif
  45.  
  46. typedef int XImage;
  47. typedef int Pixmap;
  48.  
  49. typedef struct {
  50.     USHORT red, green, blue, gray;
  51. } ColorReg;
  52.  
  53. typedef struct XA_ACTION_STRUCT{
  54.     LONG type;                    /* type of action */
  55.     LONG cmap_rev;                /* rev of cmap */
  56.     UBYTE *data;                /* data ptr */
  57.     struct XA_ACTION_STRUCT *next;
  58.     struct XA_CHDR_STRUCT *chdr;
  59.     ColorReg *h_cmap;            /* For IFF HAM images */
  60.     ULONG *map;
  61.     struct XA_ACTION_STRUCT *next_same_chdr;    /* ptr to next action with same cmap */
  62. } XA_ACTION;
  63.  
  64. typedef struct XA_CHDR_STRUCT {
  65.     LONG rev;
  66.     ColorReg *cmap;
  67.     ULONG csize, coff;
  68.     ULONG *map;
  69.     ULONG msize, moff;
  70.     struct XA_CHDR_STRUCT *next;
  71.     XA_ACTION *acts;
  72.     struct XA_CHDR_STRUCT *new_chdr;
  73. } XA_CHDR;
  74.  
  75. typedef struct {
  76.     ULONG csize, coff;
  77.     UBYTE data[4];
  78. } ACT_CMAP_HDR;
  79.  
  80. typedef struct XA_FRAME_STRUCT {
  81.     XA_ACTION *act;                /* ptr to relevant Action */
  82.     LONG time;                    /* # of millisecondes */
  83. } XA_FRAME;
  84.  
  85. typedef struct {
  86.     ULONG count;                /* number of loops */
  87.     LONG cnt_var;                /* var to keep track of loops */
  88.     ULONG end_frame;            /* last frame of loop */
  89. } ACT_BEG_LP_HDR;
  90.  
  91. typedef struct ACT_END_LP_STRUCT {
  92.     ULONG *count;                /* points back to beg_lp->count */
  93.     LONG *cnt_var;                /* points back to beg_lp->cnt_var */
  94.     ULONG begin_frame;            /* first frame of loop */
  95.     ULONG *end_frame;            /* points back to beg_lp->end_frame */
  96.     XA_ACTION *prev_end_act;    /* used to nest loops during creation */
  97. } ACT_END_LP_HDR;
  98.  
  99. typedef struct XA_ANIM_HDR_STRUCT {
  100.     LONG file_num;
  101.     LONG anim_type;                /* animation type */
  102.     LONG imagex;                /* width */
  103.     LONG imagey;                /* height */
  104.     LONG imagec;                /* number of colors */
  105.     LONG imaged;                /* depth in planes */
  106.     LONG dispx;                    /* display width */
  107.     LONG dispy;                    /* display height */
  108.     LONG buffx;                    /* buffered width */
  109.     LONG buffy;                    /* buffered height */
  110.     LONG anim_flags;
  111.     LONG loop_num;                /* number of times to loop animation */
  112.     LONG loop_frame;            /* index of loop frame */
  113.     LONG last_frame;            /* index of last frame */
  114.     char *name;                    /* name of anim */
  115.     XA_FRAME *frame_lst;        /* array of Frames making up the animation */
  116.     XA_ACTION *acts;            /* actions associated with this animation */
  117.     struct XA_ANIM_HDR_STRUCT *next_file;
  118.     struct XA_ANIM_HDR_STRUCT *prev_file;
  119. } XA_ANIM_HDR;
  120.  
  121. #define ANIM_HAM       0x00000009
  122. #define ANIM_HAM6      0x00000001
  123. #define ANIM_LACE      0x00000002
  124. #define ANIM_CYCLE     0x00000004
  125. #define ANIM_HAM8      0x00000008
  126. #define ANIM_PIXMAP    0x00000100
  127. #define ANIM_PING      0x00010000
  128. #define ANIM_NOLOOP    0x00020000
  129. /* single buffered, x11_bytes_pixel */
  130. #define ANIM_SNG_BUF   0x01000000
  131. /* double buffered, 1 byte per pixel */
  132. #define ANIM_DBL_BUF     0x02000000
  133. #define ANIM_3RD_BUF     0x04000000
  134.  
  135. typedef struct {
  136.     LONG imagex;
  137.     LONG imagey;
  138.     LONG xoff;
  139.     LONG yoff;
  140. } SIZE_HDR;
  141.  
  142.  
  143. typedef struct {
  144.     ULONG(*delta) ();
  145.     ULONG flags;
  146.     ULONG xpos, ypos;
  147.     ULONG xsize, ysize;
  148.     ULONG special;
  149.     UBYTE *data;
  150. } ACT_DLTA_HDR;
  151.  
  152. /* ACT_DLTA_HDR Flag Values */
  153. #define ACT_SNGL_BUF    0x0100    /* delta is from sngl buffer anim */
  154. #define ACT_DBL_BUF     0x0200    /* delta is from sngl buffer anim */
  155. #define ACT_3RD_BUF     0x0400    /* needs 3rd buffer for HAM or Dither */
  156.  
  157. /* DELTA Return VALUES */
  158. #define ACT_DLTA_NORM   0x00000000    /* nothing special */
  159. #define ACT_DLTA_BODY   0x00000001    /* IFF BODY - used for dbl buffer */
  160. #define ACT_DLTA_XOR    0x00000002    /* delta work in both directions */
  161. #define ACT_DLTA_NOP    0x00000004    /* delta didn't change anything */
  162. #define ACT_DLTA_MAPD   0x00000008    /* delta was able to map image */
  163. #define ACT_DLTA_BAD    0x80000000    /* uninitialize value if needed */
  164.  
  165.  
  166. typedef struct STRUCT_ACT_SETTER_HDR {
  167.     XA_ACTION *work;
  168.     LONG xback, yback;
  169.     LONG xpback, ypback;
  170.     XA_ACTION *back;
  171.     LONG xface, yface;
  172.     LONG xpface, ypface;
  173.     LONG depth;
  174.     XA_ACTION *face;
  175.     struct STRUCT_ACT_SETTER_HDR *next;
  176. } ACT_SETTER_HDR;
  177.  
  178. typedef struct {
  179.     LONG xpos;
  180.     LONG ypos;
  181.     LONG xsize;
  182.     LONG ysize;
  183.     LONG psize;
  184.     UBYTE *clip;
  185.     UBYTE *data;
  186. } ACT_MAPPED_HDR;
  187.  
  188. typedef struct {
  189.     LONG xpos;
  190.     LONG ypos;
  191.     LONG xsize;
  192.     LONG ysize;
  193.     LONG psize;
  194.     LONG rbits;
  195.     LONG gbits;
  196.     LONG bbits;
  197.     UBYTE *clip;
  198.     UBYTE *data;
  199. } ACT_TRUE_HDR;
  200.  
  201. typedef struct {
  202.     LONG xpos;
  203.     LONG ypos;
  204.     LONG xsize;
  205.     LONG ysize;
  206.     LONG pk_size;
  207.     UBYTE *clip;
  208.     UBYTE data[4];
  209. } ACT_PACKED_HDR;
  210.  
  211. typedef struct {
  212.     LONG xpos;
  213.     LONG ypos;
  214.     LONG xsize;
  215.     LONG ysize;
  216.     XImage *image;
  217.     UBYTE *clip_ptr;
  218. } ACT_CLIP_HDR;
  219.  
  220. #define ACT_NOP        0x0000
  221. #define ACT_DELAY    0x0001
  222. #define ACT_IMAGE    0x0002
  223. #define ACT_CMAP    0x0003
  224. #define ACT_SIZE    0x0004
  225. #define ACT_FADE    0x0005
  226. #define ACT_CLIP    0x0006
  227. #define ACT_PIXMAP    0x0007
  228. #define ACT_SETTER    0x0008
  229. #define ACT_RAW        0x0009
  230. #define ACT_PACKED    0x0010
  231. #define ACT_DISP    0x0011
  232. #define ACT_MAPPED    0x0012
  233. #define ACT_TRUE    0x0013
  234. #define ACT_PIXMAPS    0x0014
  235. #define ACT_IMAGES    0x0015
  236. #define ACT_CYCLE    0x0016
  237. #define ACT_DELTA    0x0017
  238. #define ACT_BEG_LP    0x0100
  239. #define ACT_END_LP    0x0101
  240. #define ACT_JMP2END    0x0102
  241.  
  242. /* flags */
  243. extern LONG xa_verbose;
  244. extern LONG xa_debug;
  245. extern LONG xa_jiffy_flag;
  246. extern LONG xa_buffer_flag;
  247. extern LONG xa_optimize_flag;
  248. extern LONG xa_use_depth_flag;
  249.  
  250. #define DEBUG_LEVEL1   if (xa_debug >= 1)
  251. #define DEBUG_LEVEL2   if (xa_debug >= 2)
  252. #define DEBUG_LEVEL3   if (xa_debug >= 3)
  253. #define DEBUG_LEVEL4   if (xa_debug >= 4)
  254. #define DEBUG_LEVEL5   if (xa_debug >= 5)
  255.  
  256. #define XA_CMAP_SIZE 256
  257. #define XA_HMAP_SIZE  64
  258. #define XA_HMAP6_SIZE 16
  259. #define XA_HMAP8_SIZE 64
  260.  
  261. /* CMAP function flags for ACT_Setup_CMAP */
  262. #define CMAP_DIRECT        0x000000
  263. #define CMAP_ALLOW_REMAP    0x000001
  264.  
  265.  
  266. #define CMAP_SCALE4 4369
  267. #define CMAP_SCALE6 1040
  268. #define CMAP_SCALE8  257
  269. #define CMAP_SCALE9  128
  270. #define CMAP_SCALE11  32
  271. #define CMAP_SCALE13   8
  272. extern ULONG cmap_scale[17];
  273. extern LONG cmap_true_to_332;
  274. extern LONG cmap_true_to_gray;
  275. extern LONG cmap_true_to_1st;
  276. extern LONG cmap_true_to_all;
  277. extern LONG cmap_true_map_flag;
  278. extern LONG cmap_dither_type;
  279.  
  280. extern LONG cmap_luma_sort;
  281. extern LONG cmap_try_to_1st_flag;
  282. extern LONG cmap_map_to_1st_flag;
  283. extern LONG cmap_play_nice;
  284. extern XA_CHDR *xa_chdr_start;
  285. extern XA_CHDR *xa_chdr_cur;
  286. extern XA_CHDR *xa_chdr_now;
  287. extern ColorReg *xa_cmap;
  288. extern ULONG xa_cmap_size;
  289. extern ULONG xa_cmap_off;
  290. extern ULONG *xa_cmap_map;
  291. extern LONG cmap_median_type;
  292. extern SHORT cmap_floyd_error;
  293. extern LONG cmap_map_to_one_flag;
  294. extern LONG pod_max_colors;
  295. extern LONG cmap_hist_flag;
  296. extern LONG cmap_median_bits;
  297. extern ULONG cmap_cache_size;
  298. extern ULONG cmap_cache_bits;
  299. extern ULONG cmap_cache_rmask;
  300. extern ULONG cmap_cache_gmask;
  301. extern ULONG cmap_cache_bmask;
  302. extern USHORT *cmap_cache;
  303. extern XA_CHDR *cmap_cache_chdr;
  304.  
  305. extern ULONG xa_r_shift, xa_g_shift, xa_b_shift;
  306. extern ULONG xa_r_mask, xa_g_mask, xa_b_mask;
  307. extern ULONG xa_gray_bits, xa_gray_shift;
  308.  
  309. #define XA_HAM_MAP_INVALID 0xffffffff
  310. #define XA_HAM6_CACHE_SIZE   4096
  311. #define XA_HAM8_CACHE_SIZE 262144
  312.  
  313. typedef struct {
  314.     ULONG rate;                    /* rate at which to cycle colors in milliseconds */
  315.     ULONG flags;                /* flags */
  316.     ULONG size;                    /* size of color array */
  317.     ULONG curpos;                /* curpos in array */
  318.     UBYTE data[4];                /* array of cmap pixel values to cycle */
  319. } ACT_CYCLE_HDR;
  320.  
  321. /* ACT_CYCLE flags values */
  322. /* NOTE: ACTIVE isn't currently checked. It's assumed to be active or
  323.  *       else it shouldn't have been created by anim reader. */
  324. #define ACT_CYCLE_ACTIVE  0x01
  325. #define ACT_CYCLE_REVERSE 0x02
  326. #define ACT_CYCLE_STARTED 0x80000000
  327.  
  328. extern void TheEnd();
  329. extern void TheEnd1();
  330. extern void ShowAnimation();
  331. extern void ShowAction();
  332. extern void Cycle_It();
  333. extern ULONG X11_Get_True_Color();
  334. extern ULONG X11_Get_Line_Size();
  335.  
  336. /* 
  337.  * Useful Macros 
  338.  */
  339.  
  340. #define CMAP_GET_GRAY(r,g,b,scale) \
  341. ( ((scale)*((r)*11+(g)*16+(b)*5) ) >> xa_gray_shift)
  342.  
  343. #define CMAP_GET_332(r,g,b,scale) ( \
  344. ( (((r)*(scale)) & xa_r_mask) >> xa_r_shift) | \
  345. ( (((g)*(scale)) & xa_g_mask) >> xa_g_shift) | \
  346. ( (((b)*(scale)) & xa_b_mask) >> xa_b_shift) )
  347.  
  348. #define X11_Get_Bitmap_Width(x) \
  349.   ( ((x + x11_bitmap_unit - 1)/x11_bitmap_unit) * x11_bitmap_unit )
  350.  
  351. #define X11_Make_Pixel(p)  (x11_cmap_type == 0)?(p): \
  352.         ( (((p)<<24)|((p)<<16)|((p)<<8)|(p)) & x11_depth_mask )
  353.  
  354. #define XA_PIC_SIZE(p) ( (xa_use_depth_flag==TRUE)?((p) * x11_bytes_pixel): \
  355.         (p) )
  356.  
  357. #define XA_GET_TIME(t) ( (xa_jiffy_flag)?(xa_jiffy_flag):(t) )
  358.  
  359. #define XA_MEMSET(p,d,size) \
  360. { if (x11_bytes_pixel==4) { ULONG _sz=(size); \
  361.     ULONG *_lp=(ULONG *)p; while(_sz--) *_lp++ = (ULONG)(d); } \
  362.   else if (x11_bytes_pixel==2) { ULONG _sz=(size); \
  363.     USHORT *_sp=(USHORT *)p; while(_sz--) *_sp++ = (USHORT)(d); } \
  364.   else { memset(p,d,size); } \
  365. }
  366.  
  367. #define XA_REALLOC(p,cur_size,new_size) { if (new_size > cur_size) \
  368. { char *_tmp; \
  369.   if (p == 0) _tmp=(char *)malloc(new_size); \
  370.   else _tmp=(char *)realloc(p,new_size); \
  371.   if (_tmp == 0) TheEnd1("XA_Realloc: malloc err"); \
  372.   p = _tmp; cur_size = new_size; } \
  373. }
  374.  
  375. #define FREE(_p,_q) free(_p)
  376. /* For Debug
  377. #define FREE(_p,_q) { fprintf(stderr,"FREE %lx %lx\n",_p,_q); free(_p); }
  378. */
  379.